#!/bin/bash

# Run as "mask" on receiver
# then run as "mask <target>" on sender
INTERP=mx_interp

send()
{
  cat << EE
open e1 any 0 0x1234
target t $1 0 0 0x1234

# a spurious send
send s e1 t 8192 1 0x30003 1
test s

# should match 
send s e1 t 8192 3 0x30003 1
test s

# another spurious send
send s e1 t 8192 1 0x30003 1
test s

# should match 
send s e1 t 8192 4 0x40004 2
test s
# should match 
send s e1 t 8192 5 0x50005 3
test s
close e1
EE
}

recv()
{
  cat << EE
open e1 any 0 0x1234

recv r1 e1 8192 3 0x30000 c 1
recv r2 e1 8192 4 0x4 b 2
recv r3 e1 8192 5 0 bc 3
test r1
test r2
test r3

close e1
EE
}

if test -z "$1"; then
  echo "Receiving..."
  recv | ${INTERP} -v
else
  echo "Sending..."
  send $1 | ${INTERP} -v
fi

